package prod_line

func (s *sdk) start() {
	// connect serial port
	// start rx loop
	for {
		select {
		case <-s.ctx.Done():
			return
		case p := <-s.packet:
			s.packetHandler([]byte(p))
		}
	}
}

func (s *sdk) packetHandler(packet []byte) {
	var cmd = packet[0]
	switch cmd {
	case CmdResp: // 通用返回报文
		s.onResponsePacket(packet)
	case CmdStartReq: // 模具就位
		s.onReady()
	case CmdCodeReq: // 请求开始赋码
		s.onCodingReq()
	case CmdRecodeReq: // 请求开始补码
		s.onRecodingReq()
	case CmdLaserReq: // 激光打标完成确认
		s.onLaserCompleted(packet)
	case CmdCommunicateReq:
		s.onTestMe()
	}
}

func (s *sdk) onResponsePacket(packet []byte) {
	var cmd = packet[3]
	switch cmd {
	case 0xe0: // 检查结果确认
		s.onCheckConfirm()
	case 0xe1: // 赋码结果确认
		s.onCodingConfirm()
	}
}
